package com.egao.common.module.validate.enums;

import com.baomidou.mybatisplus.annotation.EnumValue;
import com.egao.common.core.exception.BusinessException;
import com.fasterxml.jackson.annotation.JsonValue;
import io.swagger.annotations.ApiModel;

import java.util.Arrays;

@ApiModel(description = "验证规则项规则枚举")
public enum ValidateRuleItemRuleEnum {

    DY(1, "等于"),
    BDY(2, "不等于"),
    BH(3, "包含"),
    BBH(4, "不包含"),
    FK(5, "非空"),
    BXK(6, "必须空"),
    QBDY(7, "前不等于"),
    HBDY(8, "后不等于"),
    ;

    @EnumValue
    private final Integer value;

    @JsonValue
    private final String label;

    public Integer getValue() {
        return value;
    }

    public String getLabel() {
        return label;
    }

    ValidateRuleItemRuleEnum(Integer value, String label) {
        this.value = value;
        this.label = label;
    }

    public static ValidateRuleItemRuleEnum getByValue(Integer value) {
        return Arrays.stream(ValidateRuleItemRuleEnum.values())
                .filter(item -> item.getValue().equals(value))
                .findFirst()
                .orElseThrow(() -> new BusinessException("枚举值不存在"));
    }

    public static ValidateRuleItemRuleEnum getByLabel(String label) {
        return Arrays.stream(ValidateRuleItemRuleEnum.values())
                .filter(item -> item.getLabel().equals(label))
                .findFirst()
                .orElseThrow(() -> new BusinessException("枚举标签不存在"));
    }
}
